module.exports = function ($scope, $modalInstance, $resource, $modal, item, flag, toaster){
    

    //查询type列表
    $scope.search = function (){
        var para = {
            'type': '3',
            'state': '1'
        }
        $resource('/api/as/goc/pelawinfo/findTypeList', {}, {}).save(para, function(res){
            if(res.errcode === 0){
                $scope.typelist = res.data.results;
            }else{
                toaster.error({title: '', body: res.errmsg});
            }
        });
    }


    init();
    function init(){
       
        $scope.lawinfo = flag ? {'flag': true} : angular.copy(item);
        $scope.search();
        console.log(item);
    }
    //保存
    $scope.save = function (){
        if($scope.lawinfo.type == undefined){
            toaster.error({title: '', body: '请选择旅游法规信息类别！'});
          return;
        }
        if($scope.lawinfo.info == undefined){
            toaster.error({title: '', body: '请输入旅游法规信息详情！'});
          return;
        }
        if($scope.lawinfo.law_title == undefined){
            toaster.error({title: '', body: '请输入旅游法规信息标题！'});
          return;
        }
        var para = {
            'law_title': $scope.lawinfo.law_title,
            'info': $scope.lawinfo.info,
            'type': $scope.lawinfo.type,
            'id' :  $scope.lawinfo.id
        }
        $resource('/api/as/goc/pelawinfo/save', {}, {}).save(para, function(res){
            if(res.errcode === 0){
                toaster.success({title: '', body: '保存成功'});
                $modalInstance.close();
            }else{
                toaster.error({title: '', body: res.errmsg});
            }
        });
    }
   
    //取消
    $scope.cancel = function () {
        $modalInstance.dismiss('cancel');
    }

};